﻿using System;
using System.Reflection;
using Microsoft.Tools.WindowsInstallerXml.Extensions;
using Microsoft.Tools.WindowsInstallerXml.Tools;

[assembly: AssemblyDefaultHeatExtension(typeof (WebProjectHeatExtension))]

namespace Microsoft.Tools.WindowsInstallerXml.Extensions
{
    public sealed class WebProjectHeatExtension
        : HeatExtension
    {
        public override HeatCommandLineOption[] CommandLineTypes
        {
            get { return new HeatCommandLineOption[0]; }
        }

        public override void ParseOptions(String type, String[] args)
        {
            var harvester = Core.Harvester.Extension as VSProjectHarvester;

            if (harvester != null)
            {
                // Hijack this harvester                
                var webHarvester = new VsWebProjectHarvester(harvester);

                FieldInfo field = Core.Harvester.GetType().GetField("harvesterExtension",
                                                                    BindingFlags.GetField | BindingFlags.NonPublic |
                                                                    BindingFlags.SetField | BindingFlags.Instance);

                if (field != null)
                {
                    field.SetValue(Core.Harvester, webHarvester);
                }
            }
        }
    }
}